package com.hc.sss.llz.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hc.sss.common.ResultMap;
import com.hc.sss.pojo.Conservator;
import com.hc.sss.service.ConservatorService;

@Controller
@RequestMapping("conservator")
public class ConservatorController {

	@Autowired
	ConservatorService conservatorService;
	
	
	//管理员登录
	@RequestMapping("/login")
	@ResponseBody
	public int getSysUserList(Conservator conservator,HttpServletRequest request){
		int result = 0;
		conservator = conservatorService.conservatorLogin(conservator);
		if(conservator!=null) {
			request.getSession().setAttribute("conservator", conservator);
			result = 1;
		}
		return result;
	};
	
	//查询所有管理员分页
	@RequestMapping("/findConservatorList")
	@ResponseBody
	public ResultMap<Conservator> findConservatorList(Integer page,Integer limit){
		Map<String, Object> paramMap = new HashMap<>();
		paramMap.put("page", page);
		paramMap.put("limit", limit);
		ResultMap<Conservator> resultMap = conservatorService.findConservatorList(paramMap);
		return resultMap;
	};
	
	//获取session登录对象
	@RequestMapping("/getSession")
	@ResponseBody
	public Conservator getSession(HttpServletRequest request) {
		Conservator conservator = (Conservator) request.getSession().getAttribute("conservator");
		return conservator;
	}
	
	//修改密码
	@RequestMapping("/updateConservator")
	@ResponseBody
	public int updateConservator(Conservator conservator) {
		return conservatorService.updateConservator(conservator);
	}
	
	
	
	
	
}
